#ifndef VDMESWEBVIEW_H
#define VDMESWEBVIEW_H

#include <QWebView>
#include <QTime>
#include "VDStrings.h"

class VDUser;

class Message
{
public:
	Message() : m_pUser(NULL)
	{}

	Message(const VDUser *pUser, const QString &text, const QString &textDecor, bool isChat = false)
		: m_pUser(pUser)
		, m_text(text)
		, m_textDecor(textDecor)
		, m_isChat(isChat)
	{
		m_time = QTime::currentTime();
	}

	const VDUser *m_pUser;
	QString m_text;
	QString m_textDecor;
	QTime m_time;
	bool m_isChat;
};

class VDSmiles;

class VDMesWebView : public QWebView
{
	Q_OBJECT

public:
	VDMesWebView(const VDSmiles &smiles, QWidget *parent);
	~VDMesWebView();

	void addMesUser(const QString &mes, const VDUser &u);
	void addChatUser(const QString &mes, const VDUser &u);
	void addMesMaster(const QString &mes);
	void addChatMaster(const QString &mes);

	const Message* getLastMesUser() const;

private:
	void clear();
	QString makePage();

private:
	const VDSmiles &m_smiles;

	typedef QVector<Message*> KMessages;
	KMessages m_messages;
	QString m_strPageBegin;
	QString m_strPageEnd;
	QString m_strReplicaMaster;
	QString m_strReplicaUser;
	QUrl m_url;

private slots:
	void slotMoveToEnd();
};

#endif // VDMESWEBVIEW_H
